package b_lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
    重写的方法带参数
 */
public class Demo02Comparator {
    public static void main(String[] args) {
        //集合 of
        //List.of() -> 生成一个固定的集合 -> Arrays.asList()
        List<String> list = List.of("lucy", "tom", "marry", "jack", "rose");

        //对集合进行排序
        list = new ArrayList(list);
        System.out.println(list);

        //匿名内部类方式:
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });

        //优化:
        Collections.sort(list,(String o1,String o2) -> {
            return o1.compareTo(o2);
        });



    }
}
